using UnityEngine;
/// <summary>
/// 传送门
/// </summary>
public class transDoor : MonoBehaviour
{
    public GameObject destination;
    // Start is called before the first frame update
    void Start()
    {

    }

    // Update is called once per frame
    void Update()
    {

    }
    private void OnTriggerEnter2D(Collider2D collision)
    {
        if (collision.gameObject.tag == "Player")
        {
            collision.gameObject.GetComponent<state>().isInTransDoor = true;
        }
    }
    private void OnTriggerStay2D(Collider2D collision)
    {
        if (collision.gameObject.tag == "Player")
        {

            if (Input.GetKey(collision.gameObject.GetComponent<playerControl>().up)
                && collision.gameObject.GetComponent<state>().movementState != state.MovementState.PLAY_SKILL
                && collision.gameObject.GetComponent<state>().movementState != state.MovementState.HURTING
                && collision.gameObject.GetComponent<playerControl>()._controller.isGrounded
                )
            {

                collision.gameObject.transform.position = destination.transform.position;
                collision.gameObject.GetComponent<playerControl>()._velocity.x = 0;
                collision.gameObject.GetComponent<playerControl>()._velocity.y = 0;
            }
        }

    }
    private void OnTriggerExit2D(Collider2D other)
    {
        if (other.gameObject.tag == "Player")
        {
            other.gameObject.GetComponent<state>().isInTransDoor = false;
        }

    }
}
